package com.itheima.easy.mapper;

import com.itheima.easy.entity.AccraditationRecord;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author sjqn
 * @date 2023/6/20
 */
@Mapper
public interface AccraditationRecordMapper {


    @Select("select * from accraditation_record where bussniess_id = #{bussniessId} order by step_no")
    public List<AccraditationRecord> getAccraditationRecordByBuisId(long bussniessId);

    @Select("select * from accraditation_record where bussniess_id = #{bussniessId} order by step_no desc limit 1")
    public AccraditationRecord getLastByBuisId(long bussniessId);

    public void insert(AccraditationRecord accraditationRecord);

    @Select("select * from accraditation_record where bussniess_id = #{bussniessId} and approver_id = #{approverId} order by step_no desc limit 1")
    AccraditationRecord selectByBussniessIdAndApproverId(@Param("bussniessId") long bussniessId, @Param("approverId")Long approverId);

    @Delete("delete from accraditation_record where bussniess_id = #{bussniessId}")
    void deleteByBussniess(long bussniessId);

    @Select("select * from accraditation_record where bussniess_id = #{bussniessId} and step_no = #{stepNo}")
    AccraditationRecord selectByBussniessAndSetpNo(@Param("bussniessId")long bussniessId, @Param("stepNo")int stepNo);
}
